<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiFlowApplyTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_flow_apply';

    /**
     * Run the migrations.
     * @table qii_flow_apply
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id')->comment('Apply ID');
            $table->unsignedInteger('user_id')->default('0')->comment('流程步骤申请发起人');
            $table->unsignedInteger('category_id')->default('0')->comment('流程模型ID');
            $table->unsignedInteger('step_id')->default('0')->comment('当前所在流程步骤ID');
            $table->unsignedInteger('create_time')->default('0')->comment('创建时间');
            $table->unsignedInteger('examine_time')->default('0')->comment('审批时间');
            $table->unsignedInteger('ikey')->default('0')->comment('待审数据主键');
            $table->unsignedSmallInteger('is_agree')->default('0')->comment('审批结果(0待审批,1审批通过,2驳回)');
            $table->unsignedSmallInteger('is_over')->default('0')->comment('审批是否已经终止(0未终止 1已终止)');

            $table->index(["user_id", "category_id", "step_id"], 'user_cate_step');

            $table->index(["is_agree", "is_over"], 'agree_over');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
